#include "dog.h"

// 实例结构
typedef struct {
    MyAnimal parent;
    gchar *name;
} MyDog;

// 实现类型注册
G_DEFINE_TYPE(MyDog, my_dog, MY_TYPE_ANIMAL)

// 狗的发声实现
static void my_dog_speak(MyAnimal *animal) {
    MyDog *self = MY_DOG(animal);
    g_print("(Dog) %s: Woof!\n", self->name);
}

// 类初始化
static void my_dog_class_init(MyDogClass *klass) {
    MyAnimalClass *animal_class = MY_ANIMAL_CLASS(klass);
    animal_class->speak = my_dog_speak;
}

// 实例初始化
static void my_dog_init(MyDog *self) {
    self->name = NULL;
}

// 析构函数
static void my_dog_dispose(GObject *gobject) {
    MyDog *self = MY_DOG(gobject);
    g_free(self->name);
    G_OBJECT_CLASS(my_dog_parent_class)->dispose(gobject);
}

// 注册析构函数
static void my_dog_class_intern_init(MyDogClass *klass) {
    GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
    gobject_class->dispose = my_dog_dispose;
}

// 构造函数
MyDog *my_dog_new(const gchar *name) {
    MyDog *self = g_object_new(MY_TYPE_DOG, NULL);
    self->name = g_strdup(name);
    return self;
}